package com.atm.controller;

import com.atm.annotation.NeedLogin;
import com.atm.service.AccountService;
import com.atm.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
public class CashController {

    @Resource
    private AccountService accountService;

    @ApiOperation("取款")
    @NeedLogin
    @PostMapping("/cash")
    public Result<Boolean> cash(Long cashAmount, HttpServletRequest httpServletRequest){
        if(cashAmount<500000&&cashAmount%10000==0)
            return accountService.cash(cashAmount,httpServletRequest.getAttribute("accountNo").toString());
        return Result.fail("输入错误,取款金额必须为100的倍数并且小于5000");
    }
}
